package com.example.library.view;

import android.text.Html;

import com.example.library.http.KnowledgeParseEntity;
import com.example.library.viewmodle.CheckWordDialogViewModel;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean.MeanCollectionBean.SenCollectionBean;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean.MeanCollectionBean;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean.CollCollectionBean.CollSenCollectionBean;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean.CollCollectionBean;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean.DiscCollectionBean;
import com.example.library.http.KnowledgeParseEntity.CxCollectionBean.ClassCollectionBean;
import com.orhanobut.logger.Logger;


/**
 * Created by dadong on 2018/8/28.
 * Describe:
 */
public class NewDealDataUtil {
    public static CheckWordDialogViewModel getViewModel(CheckWordDialogViewModel viewModel, KnowledgeParseEntity entity) {
        if (viewModel == null || entity == null) {
            return new CheckWordDialogViewModel();
        }
        viewModel.knowledge.set(entity.getCwName());
        viewModel.englishPronunciation.set(entity.getUsPVoice());
        viewModel.americanPronunciation.set(entity.getUnPVoice());
        viewModel.unPText.set(Html.fromHtml(entity.getUnPText()).toString());
        viewModel.usPText.set(Html.fromHtml(entity.getUsPText()).toString());
        //释义例句
        if (entity.getCxCollection() != null && entity.getCxCollection().size() > 0) {
            for (int i = 0; i < entity.getCxCollection().size(); ++i) {
                CxCollectionBean cxCollectionBean = entity.getCxCollection().get(i);
                if (cxCollectionBean.getMeanCollection() == null || cxCollectionBean.getMeanCollection().size() <= 0) {
                   continue;
                }
                for (int j = 0; j < cxCollectionBean.getMeanCollection().size(); ++j) {
                    MeanCollectionBean meanCollectionBean = cxCollectionBean.getMeanCollection().get(j);
                    for (SenCollectionBean senCollectionBean : meanCollectionBean.getSenCollection()) {
                        SenCollectionBean bean = new SenCollectionBean();
                        bean.setChineseMeaning(meanCollectionBean.getChineseMeaning());
                        bean.setCxEnglish(cxCollectionBean.getCxEnglish());
                        bean.setSentenceEn(senCollectionBean.getSentenceEn());
                        bean.setSTranslation(senCollectionBean.getSTranslation());
                        bean.setSViocePath(senCollectionBean.getSViocePath());
                        viewModel.senCollectionBeans.add(bean);
                    }
                }
            }

            //常用搭配
            for (int i = 0; i < entity.getCxCollection().size(); ++i) {
                CxCollectionBean cxCollectionBean = entity.getCxCollection().get(i);
                if (cxCollectionBean.getCollCollection() == null || cxCollectionBean.getCollCollection().size() <= 0) {
                    continue;
                }
                for (int j = 0; j < cxCollectionBean.getCollCollection().size(); ++j) {
                    CollCollectionBean collCollectionBean = cxCollectionBean.getCollCollection().get(j);
                    for (CollSenCollectionBean senCollectionBean : collCollectionBean.getCollSenCollection()) {
                        CollSenCollectionBean collSenCollectionBean = new CollSenCollectionBean();
                        collSenCollectionBean.setColl_SenChi(senCollectionBean.getColl_SenChi());
                        collSenCollectionBean.setCxEnglish(cxCollectionBean.getCxEnglish());
                        collSenCollectionBean.setColl_SenEng(senCollectionBean.getColl_SenEng());
                        collSenCollectionBean.setColl_English(collCollectionBean.getColl_English());
                        viewModel.collSenCollectionBeans.add(collSenCollectionBean);
                    }
                }
            }

            //辨析
            for (int i = 0; i < entity.getCxCollection().size(); ++i) {
                CxCollectionBean cxCollectionBean = entity.getCxCollection().get(i);
                if (cxCollectionBean.getDiscCollection() == null || cxCollectionBean.getDiscCollection().size() <= 0) {
                    continue;
                }
                for (int j = 0; j < cxCollectionBean.getDiscCollection().size(); ++j) {
                    DiscCollectionBean discCollectionBean = new DiscCollectionBean();
                    discCollectionBean.setCxEnglish(cxCollectionBean.getCxEnglish());
                    discCollectionBean.setDescription(cxCollectionBean.getDiscCollection().get(j).getDescription());
                    discCollectionBean.setWord(cxCollectionBean.getDiscCollection().get(j).getWord());
                    viewModel.discCollectionBeans.add(discCollectionBean);
                    Logger.d(cxCollectionBean.getDiscCollection().get(j).getDescription() + "shishisaonian");
                }
            }

            //经典例句
            for (int i = 0; i < entity.getCxCollection().size(); ++i) {
                CxCollectionBean cxCollectionBean = entity.getCxCollection().get(i);
                if (cxCollectionBean.getClassCollection().size() <= 0 || cxCollectionBean.getClassCollection() == null) {
                   continue;
                }
                for (int j = 0; j < cxCollectionBean.getClassCollection().size(); ++j) {
                    ClassCollectionBean classCollectionBean = new ClassCollectionBean();
                    classCollectionBean.setClassicApp(cxCollectionBean.getClassCollection().get(j).getClassicApp());
                    classCollectionBean.setCxEnglish(cxCollectionBean.getCxEnglish());
                    viewModel.classCollectionBeans.add(classCollectionBean);
                }
            }
        }
        return viewModel;
    }
}
